package com.project.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.ManBean;
import com.project.mapper.IManMapper;
import com.project.service.IManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

@Service   //声明该类为业务组件类
@Transactional  //该类中所有方法需要进行事务管理
public class ManServiceImpl implements IManService {
    private final int PAGESIZE = 3;
    @Autowired
    private IManMapper mapper;
    @Override
    public void add(ManBean man) {
        mapper.add(man);
    }

    @Override
    public void del(int id) {
        mapper.del(id);
    }

    @Override
    public void update(int id, LocalDate birthday) {
        mapper.update(id, birthday);
    }

    @Override
    public List<ManBean> findAll() {
        return mapper.findAll();
    }

    @Override
    public PageInfo<ManBean> findByItem(int pageNo, String name, LocalDate start, LocalDate end) {
        PageHelper.startPage(pageNo,PAGESIZE);
        PageInfo<ManBean> info= PageInfo.of(mapper.findByItem(name, start, end));
        return info;
    }
}
